package cn.wolfcode.web.controller;


import cn.wolfcode.domain.MessageReplyHzh;
import cn.wolfcode.service.IMessageReplyHzhService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ModelAttribute;

@Controller
@RequestMapping("/messageReplyHzh")
public class MessageReplyHzhController {

    @Autowired
    private IMessageReplyHzhService messageReplyHzhService;


    @RequiredPermission(name="留言回复页面",expermission="messageReplyHzh:list")
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo){
        PageInfo<MessageReplyHzh> pageInfo = messageReplyHzhService.query(qo);
        model.addAttribute("pageInfo", pageInfo);
        return "messageReplyHzh/list";
    }


    @RequiredPermission(name="留言回复删除",expermission="messageReplyHzh:delete")
    @RequestMapping("/delete")
    public String delete(Long id) {
        if (id != null) {
           messageReplyHzhService.delete(id);
        }
        return "redirect:/messageReplyHzh/list";
    }


    @RequiredPermission(name="留言回复新增/编辑",expermission="messageReplyHzh:saveOrUpdate")
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(MessageReplyHzh messageReplyHzh) {
        if (messageReplyHzh.getId() == null) {
            messageReplyHzhService.save(messageReplyHzh);
        } else {
            messageReplyHzhService.update(messageReplyHzh);
        }
        return "redirect:/messageReplyHzh/list";
    }


    @RequiredPermission(name="留言回复新增/编辑",expermission="messageReplyHzh:saveOrUpdate")
    @RequestMapping("/input")
    public String input(Long id, Model model) {
        if (id != null) {
            model.addAttribute("messageReplyHzh",messageReplyHzhService.get(id));
        }
        return "messageReplyHzh/input";
    }
}
